home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / nghelp.zip / NG.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-02  |  16KB  |  649 lines

  1. {$A+,B-,E+,F-,I-,N-,O-,R-,V-}
  2. {$UNDEF DEBUG}
  3. {$IFDEF DEBUG} {$D+,L+,S+} {$ELSE} {$D-,L-,S-} {$ENDIF}
  4. Unit Ng;
  5.  
  6. Interface
  7.  
  8. Const ShortEntry = 0;
  9.       LongEntry  = 1;
  10.       NoEntry    = $ffff;
  11.  
  12. Type Str79   = String[79];
  13.      Str84   = String[84];
  14.      Str100  = String[100];
  15.      Str160  = String[160];
  16.      Str255  = String[255];
  17.      StrPtr  = ^Str84;
  18.  
  19.  
  20. {**********De Objecten*******************************************************}
  21.      GuideMenuOBJ     = Object
  22.       Count           : Word; {Aantal Pulldownmenus in dit Menu,Contructor}
  23.       Title           : Str84;
  24.       {********Pointers***************************}
  25.       Entrys          : Array [1..10] of Longint;
  26.       Lines           : Array [1..10] of StrPtr;
  27.       {*******************************************}
  28.  
  29.       Procedure Load(L : Longint); {Laad menuEntry}
  30.       Procedure Done;{voor straks Desctructor}
  31.       Function Entry(Nr : Word) : Longint; {Zie MMEntry}
  32.       Function Line(Nr : Word) : Str84;
  33.      End; {GuideMenuOBJ}
  34. {****************************************************************************}
  35.      GuideShortOBJ    = Object
  36.       Count           : Word; {Aantal regels, 0 als fout is opgetreden}
  37.       Parent          : Longint; {Geeft ouders van ouder in short}
  38.       Current         : Word; {Current Entry,Eigenlijk +1, Als Parent -1}
  39.                               {dan Current 65536                        }
  40.       MenuParent      : Word; {als Parent -1 dan is dit het Menu Nummer}
  41.                               {Eerste Menu is 0}
  42.       MenuLine        : Word; {Als Parent -1 Dan dit Regelnummer van menu}
  43.                               {Eerste Regel is 0}
  44.       {********Pointers***************************}
  45.       Entrys          : Array [1..512] of Longint;
  46.       Lines           : Array [1..512] of StrPtr;
  47.       {*******************************************}
  48.  
  49.       Procedure Load(L : Longint); {laad een short entry}
  50.       Procedure Done; {Voor later met destructor}
  51.       Function Line(Nr : Word) : Str84;
  52.       Function RawLine(Nr : Word) : Str84;
  53.       Function Entry(Nr : Word) : Longint;
  54.      End; {GuideShortOBJ}
  55. {****************************************************************************}
  56.      SeeAlsoOBJ        = Object
  57.       Count            : Word;
  58.  
  59.       {********Pointers***************************}
  60.       Entrys          : Array [1..21] of Longint;
  61.       Lines           : Array [1..21] of StrPtr;
  62.       {*******************************************}
  63.  
  64.       Procedure Done;
  65.       Function Line(Nr : Word) : Str84;
  66.       Function Entry(Nr : Word) : Longint;
  67.      End; {SeeAlso}
  68. {----------------------------------------------------------------------------}
  69.      GuideLongOBJ     = Object
  70.       SeeAlso         : SeeAlsoObj;
  71.       Count           : Word; {Aantal Regels}
  72.       Parent          : Longint; {Als -1 dan geen parent}
  73.       Current         : Word; {Als 65535 dan geen Current}
  74.       MenuParent      : Word; {Let op menu 4 = Menu 0}
  75.       MenuLine        : Word; {Begint bij 0 net als boven}
  76.       PrevEntry       : Longint; {-1 geen previous}
  77.       NxtEntry        : Longint; {-1 geen next}
  78.  
  79.       {********Pointers***************************}
  80.       Lines           : Array [1..512] of StrPtr;
  81.       {*******************************************}
  82.  
  83.       Procedure Load(L : Longint);
  84.       Procedure Done;
  85.       Function Line(Nr : Word) : Str84;
  86.       Function RawLine(Nr : Word) : Str84;
  87.       Function Previous : Longint;
  88.       Function Next : Longint;
  89.      End; {GuideLongOBJ}
  90.  
  91.  
  92.  
  93. {**********Einde van de Objecten*********************************************}
  94.  
  95.  
  96. Var GuideName : Str84;
  97.     Menus     : Byte; {De aantal topmenus}
  98.  
  99. {**Algemeen voor NG**********************************************************}
  100. Function  LookGuide(F : String) : String;
  101. Function  OpenGuide(GuideFileName : Str79) : Boolean;
  102. Procedure CloseGuide;
  103. Function  Credit(Regel : Byte) : Str160;
  104. Function  MenuEntry(Nr : Byte) : Longint;
  105. Function  EntryType(L : Longint) : Word;
  106. Function  GuideStrip(S : String) : String;
  107. Function  FirstEntry : Longint;
  108. {****************************************************************************}
  109.  
  110. Implementation
  111.  
  112. {Algemeen gebruikte variabelen}
  113. {Geen object omdat NG.TPU Maar een NG file Open per keer aankan}
  114. Var DecrypTabel  : Array [0..255] of Byte;
  115.     Guide        : File; {File variabele voor Norton Guide}
  116.     MEntry       : Array [1..10] of Longint; {Geeft MenuEntrys voor Menuobj.Load}
  117.     Credits      : Array [1..5] of StrPtr;{voor funtie Credit}
  118.     Buffer       : Array [0..377] of Byte;
  119.     UpDateBuffer : Boolean;
  120.     FileBufStart : Longint;
  121.     FilePtr      : Longint;
  122.     FileBufEnd   : Longint;
  123.  
  124. {***Niet voor eind user maar voor intern, menuobj****************************}
  125. {----------------------------------------------------------------------------}
  126.  
  127. {**Algemeen Voor Norton Guide*************************************************}
  128. Procedure MoveFilePtr(L : Longint);
  129. {deze procedure doet een normale seek, is gedaan om bij eventueele fout
  130.  controle dit hier te inplanteren. FilePtr wordt ook geupdate omdat enkele
  131.  funties hier vanaf hangen(bv:GuideShortOBJ.load de Entrys Lezen)}
  132. Begin
  133.  Seek(Guide,L);
  134.  if (L>=FileBufStart) And (L<=FileBufEnd) then FilePtr := L
  135.   Else UpDateBuffer := True;
  136. End;
  137.  
  138.  
  139. Procedure ReadBuffer;
  140. Var Result : Word;
  141. Begin
  142.  if Not UpDateBuffer then Seek(Guide,FilePtr);
  143.  UpDateBuffer := False;
  144.  FileBufStart := FilePos(Guide);
  145.  FilePtr := FileBufStart;
  146.  BlockRead(Guide,Buffer,Sizeof(Buffer),Result);
  147.  FileBufEnd := FilePtr + Pred(Result);
  148. End;
  149.  
  150.  
  151. Procedure MakeDecrypTabel;
  152.  
  153.   Function Decrypt(B  : Byte) : Byte;
  154.   {Decrypt byte from NG format}
  155.   Begin
  156.    if ((B Mod 32)>=16) then B := B - 16 Else B := B + 16;
  157.    if ((B Mod 16)>=8) then  B := B - 8  Else B := B + 8;
  158.    if ((B Mod 4)>=2) then   B := B - 2  Else B := B + 2;
  159.    Decrypt := B;
  160.   End;
  161.  
  162. Var Loop : Byte;
  163. Begin
  164.  For Loop := 0 to 255 Do DecrypTabel[Loop] := Decrypt(Loop);
  165. End;
  166.  
  167.  
  168. Function Read_Byte : Byte;
  169. {Read and decrypt byte}
  170. Var Tb : Byte;
  171. Begin
  172.  if (FilePtr>FileBufEnd) Or (UpDateBuffer) then
  173.   Begin
  174.    ReadBuffer;
  175.   End;
  176.  Tb := DecrypTabel[Buffer[FilePtr-FileBufStart]];
  177.  Inc(FilePtr);
  178.  Read_Byte := Tb;
  179. End;
  180.  
  181.  
  182. Function Read_Word : Word;
  183. {Read and decrypt word}
  184. Var Tw : Word;
  185.     Tb : Byte;
  186. Begin
  187.  Tb := Read_Byte;
  188.  Tw := Tb;
  189.  Tb := Read_Byte;
  190.  Inc(tw,(Tb*256));
  191.  Read_Word := Tw;
  192. End;
  193.  
  194.  
  195. Function Read_Long : Longint;
  196. {Read and decrypt longint}
  197. Var Tl : Longint;
  198.     Tw : Word;
  199. Begin
  200.  Tw := Read_Word;
  201.  Tl := Tw;
  202.  Tw := Read_Word;
  203.  Inc(Tl,(Tw*65536));
  204.  Read_Long := Tl;
  205. End;
  206. {******************Eind Norton Algemeen**************************************}
  207.  
  208. {*****Normale Functies en Procedures*****************************************}
  209. Procedure CloseGuide;
  210. Var Loop : Byte;
  211. Begin
  212. {$I-} Close(Guide); {$I+}
  213.  if IOResult <> 0 then ; {Alleen opvangen}
  214.  
  215.  For Loop := 1 to 5 Do
  216.   if Credits[Loop]<>Nil then FreeMem(Credits[Loop],Length(Credits[Loop]^)+1);
  217. End;
  218.  
  219.  
  220. Function FirstEntry : Longint;
  221. Begin
  222.  FirstEntry := 378;
  223. End;
  224.  
  225.  
  226. Function LookGuide(F : String) : String;
  227. Var S            : String;
  228.     Loop         : Word;
  229.     Result       : Word;
  230.     Guide        : File;
  231. Begin
  232.  LookGuide := ''; UpDateBuffer := True;
  233.  if F = '' then Exit;
  234.  
  235.  Assign(Guide,F);
  236. {$I-} Reset(Guide,1); {$I+}
  237.  if IOResult <> 0 then Exit; {File bestaat niet}
  238.  BlockRead(Guide,Buffer,378,Result);
  239.  if (Buffer[0]<>78) Or (Buffer[1]<>71)
  240.  Or (Result<>Sizeof(Buffer)) then
  241.  {Als de eerste 2 char niet 'NG' zijn of file is te klein dan geen NortonGuide}
  242.   Begin
  243.    Close(Guide);
  244.    Exit;
  245.   End;
  246.  
  247.  Menus := Buffer[6];
  248.  
  249.  Loop := 0;
  250.  Repeat
  251.   S[Loop+1] := Chr(Buffer[Loop+8]);
  252.   Inc(Loop);
  253.  Until (Buffer[Loop+8]=0);
  254.  S[0] := Chr(Loop); {Lengte Van de GuideName}
  255.  LookGuide := S;
  256.  
  257.  Close(Guide);
  258. End;
  259.  
  260.  
  261. Function OpenGuide(GuideFileName : Str79) : Boolean;
  262. Var Loop         : Word;
  263.  
  264.   Procedure GetCredits;
  265.   Var Loop2 : Byte;
  266.       Len   : Byte;
  267.       S     : String;
  268.   Begin
  269.    Loop := 48;
  270.    For Loop2 := 1 to 5 Do
  271.     Begi